<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/8/25
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>分诊</title>
    <link href="${pageContext.request.contextPath}/layui/css/layui.css" type="text/css" rel="stylesheet" media="all"/>
    <style type="text/css">
        .layui-table-cell{
            height: auto;
            line-height: 28px;
        }

    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script type="text/javascript">
        layui.config({
            version: true //一般用于更新组件缓存，默认不开启。设为true即让浏览器不缓存。也可以设为一个固定的值，如：201610
        });
        //首页展示
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#myTable',//一般是id选择器
                url:"triage/showPage",//数据接口，请求地址
                page: true,//开启分页
                where:{"id":${param.id}},
                cols: [[ //表头
                    {type:"checkbox",align:"center"},
                    {field: 'triageid',title:'编号'},
                    {field: 'patient.patientname', title: '患者',templet:'#nameTemplet'},
                    {field: 'patient.patientsex', title: '性别',templet:'#priceTemplet'},
                    {field: 'patient.birth', title: '出生年日',templet:'#birthTemplet'},
                    {field: 'triagestatus', title: '诊断状态',templet:'#statusTemplet'},
                    {title:'操作',toolbar:"#caozuo"}
                ]]
            });
        });

        function tanchu(){
            layui.use('layer', function(){
                var layer = layui.layer;
                //layer.msg('hello');
                layer.open({
                    type:1,
                    content:$("#myForm"),
                    area: ['500px', '600px'],
                    maxmin:true
                })
            });
        }
        //执行添加和修改操作

        layui.use(['layer','form','table'], function() {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            form.on("submit(zd)",function (data) {
                $.ajax({
                    url:"triage/update",
                    data:data.field,
                    type:"post",
                    success:function (data) {

                        layer.closeAll('page')
                        if (data.Result){
                            layer.alert("诊断成功",{time:3000})
                        } else {
                            layer.alert("诊断失败",{time:3000})
                        }
                        table.reload("myTable")
                    }
                })
            })
        })
        layui.use('table', function() {
            var table = layui.table;
            //监听工具条
            table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                //console.log(data.bookid)
                if(layEvent === 'zhenduan'){ //诊断
                    tanchu();
                    $.ajax({
                        url:"triage/selectOne",
                        data:"id="+data.triageid,
                        type:"post",
                        success:function (data) {
                            $("#patientid").prop("value",data.triage.triageid);
                            $("#patientname").val(data.triage.patient.patientname);
                            $("#departmentid").val(data.triage.department.departmentid);
                            $("#departmentname").val(data.triage.department.departmentname);
                            $("#userid").val(data.triage.user.userid);
                            $("#username").val(data.triage.user.username);
                            $("#illnessinfo").val("");
                            $("#advice").val("");
                        }
                    })
                }
            });
        })

        //时间
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#birth' //指定元素
            });
        });

    </script>
    <script type="text/html" id="priceTemplet">
        {{#  if(d.patient.patientsex == 1){ }}
        男
        {{#  } else { }}
        女
        {{#  } }}
    </script>
    <script type="text/html" id="statusTemplet">
        {{#  if(d.triagestatus == 1){ }}
        诊断结束
        {{#  } else { }}
        等待诊断
        {{#  } }}
    </script>
    <script type="text/html" id="idTemplet">
        {{d.patient.patientid}}
    </script>
    <script type="text/html" id="nameTemplet">
        {{d.patient.patientname}}
    </script>
    <script type="text/html" id="birthTemplet">
        {{d.patient.birth}}
    </script>
</head>
<body>
    <table id="myTable" lay-filter="test"></table>

    <div id="caozuo" style="display: none">
        <div>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="zhenduan">诊断</button>
        </div>
    </div>
    <%--弹出层--%>
    <form class="layui-form" id="myForm" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">患者编号</label>
            <div class="layui-input-block">
                <input type="text" name="triageid" id="patientid" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">患者名字</label>
            <div class="layui-input-block">
                <input type="text" name="patient.patientname" id="patientname" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科室编号</label>
            <div class="layui-input-block">
                <input type="text" name="department.departmentid" id="departmentid" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科室</label>
            <div class="layui-input-block">
                <input type="text" name="department.departmentname" id="departmentname" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">医生编号</label>
            <div class="layui-input-block">
                <input type="text" name="user.userid" id="userid" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">医生姓名</label>
            <div class="layui-input-block">
                <input type="text" name="user.username" id="username" required  lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">症状描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="illnessinfo" id="illnessinfo"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">症状意见</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="advice" id="advice"></textarea>
            </div>
        </div>


        <button class="layui-btn" type="button" lay-submit lay-filter="zd">诊断</button>
        <button class="layui-btn" type="reset">重置</button>
    </form>
</body>
</html>
